package com.halobop.demo.config;

import com.halobop.demo.exception.IErrorInfo;
import com.halobop.demo.exception.TestException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常捕获累
 * @author :  ChadXiao
 * @date : 2019-09-07 11:12
 * @email : chad.xiao@halobop.com
 */
@RestControllerAdvice
public class MyErrorHandler {

    @ExceptionHandler(value = RuntimeException.class)
    public String handleRuntimeError(RuntimeException e){
        e.printStackTrace();
        return "runTimeError";
    }

    @ExceptionHandler(value = TestException.class)
    public String handleTextError(TestException e){
        e.printStackTrace();
        return "errorCode:" + ((IErrorInfo)e).getCode() + " errorMessage:" + ((IErrorInfo)e).getReturnMessage();
    }

}
